//
//  View.c
//  LearnC
//
//  Created by 劉裕 on 10/10/2016.
//  Copyright © 2016 劉裕. All rights reserved.
//

#include <CoreGraphics/CoreGraphics.h>
#include <objc/runtime.h>

Class ViewClass;

extern CGContextRef UIGraphicsGetCurrentContext();

void View_drawRect(id self, SEL _cmd, CGRect rect) {
    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetFillColor(context, (CGFloat[]) {1, 0, 0, 1});
    CGContextAddRect(context, (struct CGRect) {0, 0, 320, 568});
    CGContextFillPath(context);
}

__attribute__((constructor))
static void initView() {
    ViewClass = objc_allocateClassPair((Class) objc_getClass("UIView"), "View", 0);
    class_addMethod(ViewClass, sel_getUid("drawRect:"), (IMP) View_drawRect, "v@:");
    objc_registerClassPair(ViewClass);
}
